package com.ruoyi.hov.controller;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hov.entity.Hov;
import com.ruoyi.hov.service.HovService;
import com.ruoyi.query.entity.Query;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * <p>
 * hov主表 前端控制器
 * </p>
 *
 * @author XiaShiLong
 * @since 2021-04-01
 */
@RestController
@RequestMapping("/hov")
@Api("hov主表")
public class HovController extends BaseController {

    private final HovService service;

    @Autowired
    public HovController(HovService service) {
        this.service = service;
    }

    @PreAuthorize("@ss.hasPermi('hov:post:add')")
    @Log(title = "新增hov", businessType = BusinessType.INSERT)
    @ApiOperation("新增hov")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Hov hov) {
        return toAjax(service.save(hov));
    }

    @PreAuthorize("@ss.hasPermi('hov:put:update')")
    @Log(title = "更新hov", businessType = BusinessType.UPDATE)
    @ApiOperation("更新hov")
    @PutMapping
    public AjaxResult update(@Validated @RequestBody Hov hov) {
        return toAjax(service.updateById(hov));
    }

    @PreAuthorize("@ss.hasPermi('hov:delete:delete')")
    @Log(title = "删除hov", businessType = BusinessType.DELETE)
    @ApiOperation("删除hov")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Serializable id) {
        return toAjax(service.removeById(id));
    }

    @PreAuthorize("@ss.hasPermi('hov:post:pageQuery')")
    @ApiOperation("分页查询")
    @PostMapping("/pageQuery/{page}/{size}")
    public TableDataInfo pageQuery(@PathVariable int page, @PathVariable int size, @RequestBody Query query) {
        return getDataTable(service.pageQuery(page, size, query));
    }

    @PreAuthorize("@ss.hasPermi('hov:post:getAll')")
    @ApiOperation("获取所有")
    @PostMapping("/getAll/{page}/{size}")
    public TableDataInfo getAll(@PathVariable int page, @PathVariable int size, String searchText) {
        return getDataTable(service.getAll(page, size, searchText));
    }
}
